# Recache the data if necessary
if ( !$this->manualRecache && $this->isExpired( $code ) ) {
- if ( file_exists( Language::getMessagesFileName( $code ) ) ) {
+ if ( Language::isSupportedLanguage( $code ) ) {
$this->recache( $code );
} elseif ( $code === 'en' ) {
throw new MWException( 'MessagesEn.php is missing.' );
global $IP;
wfProfileIn( __METHOD__ );
+
+ // This reads in the PHP i18n file with non-messages l10n data
$fileName = Language::getMessagesFileName( $code );
if ( !file_exists( $fileName ) ) {
- wfProfileOut( __METHOD__ );
-
- return false;
+ $data = array();
+ } else {
+ $deps[] = new FileDependency( $fileName );
+ $data = $this->readPHPFile( $fileName, 'core' );
}
- $deps[] = new FileDependency( $fileName );
- $data = $this->readPHPFile( $fileName, 'core' );
-
# Load CLDR plural rules for JavaScript
$data['pluralRules'] = $this->getPluralRules( $code );
# And for PHP
$codeSequence = array_merge( array( $code ), $coreData['fallbackSequence'] );
- # Load the extension localisations
- # This is done after the core because we know the fallback sequence now.
- # But it has a higher precedence for merging so that we can support things
- # like site-specific message overrides.
+ # Load core messages and the extension localisations.
wfProfileIn( __METHOD__ . '-extensions' );
$allData = $initialData;
foreach ( $wgMessagesDirs as $dirs ) {
* @since 1.21
*/
public static function isSupportedLanguage( $code ) {
- return $code === strtolower( $code ) && is_readable( self::getMessagesFileName( $code ) );
+ return self::isValidBuiltInCode( $code )
+ && ( is_readable( self::getMessagesFileName( $code ) )
+ || is_readable( self::getJsonMessagesFileName( $code ) )
+ );
}
/**
/**
* Returns true if a language code is of a valid form for the purposes of
- * internal customisation of MediaWiki, via Messages*.php.
+ * internal customisation of MediaWiki, via Messages*.php or *.json.
*
* @param $code string
*
# We do this using a foreach over the codes instead of a directory
# loop so that messages files in extensions will work correctly.
foreach ( $returnMw as $code => $value ) {
- if ( is_readable( self::getMessagesFileName( $code ) ) ) {
+ if ( is_readable( self::getMessagesFileName( $code ) )
+ || is_readable( self::getJsonMessagesFileName( $code ) )
+ ) {
$namesMwFile[$code] = $names[$code];
}
}
+
return $namesMwFile;
}
+
# 'mw' option; default if it's not one of the other two options (all/mwfile)
return $returnMw;
}
* @return string $prefix . $mangledCode . $suffix
*/
public static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
- // Protect against path traversal
- if ( !Language::isValidCode( $code )
- || strcspn( $code, ":/\\\000" ) !== strlen( $code )
- ) {
+ if ( !self::isValidBuiltInCode( $code ) ) {
throw new MWException( "Invalid language code \"$code\"" );
}
return $file;
}
+ /**
+ * @param $code string
+ * @return string
+ * @since 1.23
+ */
+ public static function getJsonMessagesFileName( $code ) {
+ global $IP;
+
+ if ( !self::isValidBuiltInCode( $code ) ) {
+ throw new MWException( "Invalid language code \"$code\"" );
+ }
+
+ return "$IP/languages/i18n/$code.json" ;
+ }
+
/**
* @param $code string
* @return string
$found = preg_match( '/Language(.+)Test/', get_called_class(), $m );
if ( $found ) {
# Normalize language code since classes uses underscores
- $m[1] = str_replace( '_', '-', $m[1] );
+ $m[1] = strtolower( str_replace( '_', '-', $m[1] ) );
} else {
# Fallback to english language
$m[1] = 'en';